using System;
using System.ComponentModel;
using System.Globalization;

namespace OpenWaves
{
    public class UrlTypeConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var urlString = value as string;
            if (urlString != null)
                return Url.Parse(urlString);

            return base.ConvertFrom(context, culture, value);
        }

#if !SILVERLIGHT
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            return null;
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return false;
        }
#endif
    }
}